<?php

namespace App\Http\Requests\PC\CustomerStore\PackCategory;

use App\Http\Requests\ApiRequest;
use Illuminate\Database\Query\Builder;
use Illuminate\Validation\Rule;

/**
 * @property array customer
 * @property array name
 * @property array pack_category_id
 */
class PackCategoryUpdateRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {

        return [
            'name' => [
                'sometimes','required', 'string', 'max:'.self::MAX_STRING,
                Rule::unique('pack_categories')->where($this->uniqueSameCustomer())
            ],
        ];
    }

    /**
     * @return \Closure
     */
    private function uniqueSameCustomer(): \Closure
    {
        return function (Builder $query) {
            return $query->where('customer_id', $this->customer)
                ->where('id', '<>', $this->pack_category_id);
        };
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'name.*'              => '整体妆容的名称必须是字符串',
//            'thumb.*'             => '整体妆容的缩率图必须是上传的图片',
//            'assets.*.asset_id.*' => '素材的id必须是数值',
//            'assets.*.index.*'    => '素材的形状必须是数值',
//            'assets.*'            => '单个素材的信息必须是数组',
//        ];
//    }
}
